package com.shop.service;

import com.shop.dao.user.UserDao;
import com.shop.entity.user.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.annotation.RequestScope;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestScope//用于刷新
public class UserServiceRest {
    @Autowired
    private UserDao userDao;
    /***
     * 验证用户唯一性
     * @param usercode
     * @return
     */
    @RequestMapping("findByUsername")
    public User findByUsername(String usercode){
        Map<String, Object> param=new HashMap();
        param.put("usercode", usercode);
        List<User> list= userDao.LoginUserListByMap(param);
        if(list.size() > 0) {
            return list.get(0);
        } else {
            return null;
        }
    }
    /***
     * 用于登录
     * @param usercode
     * @param userpassword
     * @return
     * @throws Exception
     */
    @RequestMapping("LoginUser")
    public User LoginUser(String usercode, String userpassword) {
        User user = this.findByUsername(usercode);
        if(null != user && user.getUserpassword().equals(userpassword)) {
            //登陆成功
            return user;
        } else {
            //登陆失败
            return null;
        }
    }
}
